#ifndef STACK_CPP
#define STACK_CPP

//#include"global.h"
#include<string>
#include<iostream>
#include<cstdlib>
using namespace std;

const int MaxSize=50;

template<class T>
class Stack
{
	public:
		T list[MaxSize];
		int top;


		Stack(){top=-1;}
		~Stack(){top=-1;}
//		Stack(const Stack& s);
		void push(T& item);
		T* pop(void);
		T* topNode();

		void errorFun(string s);
		void clearStack();
		bool isEmpty();
		bool isFull();

};


template<class T>
void Stack<T>::errorFun(string msg)
{
	cout<<msg<<endl;
	exit(1);
}

template<class T>
bool Stack<T>::isEmpty()
{
	return -1==top;

}

template<class T>
bool Stack<T>::isFull()
{
	return top==MaxSize;
}

template<class T>
void Stack<T>::push(T& item)
{
	if( isFull())
		errorFun("the stack is full, cannot push again");
		
	top++; // 此时top是0，给top所指的位置赋值
	list[top]=item;
}

template<class T>
T* Stack<T>::pop()
{
	if(isEmpty())
		errorFun("the stack is empty, cannot pop again");
	T * t=new T(list[top]);
	top--;
	return t;
}

template<class T>
T* Stack<T>::topNode()
{
	if(isEmpty())
		errorFun("the stack is empty, cannot top again");
	T * t=new T(list[top]);
	return t;
}
#endif
